<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title></title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="/static/css/font.css">
        <link rel="stylesheet" href="/static/css/xadmin.css">
        <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/js/xadmin.js"></script>
    </head>
    
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">演示</a>
                <a>
                    <cite>导航元素</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5" id="form" action="{{urlfor "admin.ArticleController.List"}}" method="get">
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input class="layui-input" placeholder="开始日" value="{{if .Start}}{{.Start}}{{end}}" name="start" id="start"></div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input class="layui-input" placeholder="截止日" value="{{if .End}}{{.End}}{{end}}"  name="end" id="end"></div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="status">
                                        <option value="">文章状态</option>
                                        <option {{if eq 1 .Status}}selected{{end}} value="1">可用</option>
                                        <option {{if eq 2 .Status}}selected{{end}} value="2">禁止</option>
                                        <option {{if eq 3 .Status}}selected{{end}} value="3">删除</option>
                                    </select>
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input value="{{if .Title}}{{.Title}}{{end}}" type="text" name="title" placeholder="请输入标题" autocomplete="off" class="layui-input"></div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <button type="reset" class="layui-btn" onclick="reset_form()"><i class="layui-icon layui-icon-refresh"></i></button>
                                    <button class="layui-btn" lay-submit="" lay-filter="sreach">
                                        <i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="xadmin.open('添加文章','{{urlfor "admin.ArticleController.Add"}}','','',true)">
                                <i class="layui-icon"></i>添加</button></div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form">
                                <thead>
                                    <tr>
                                        <th>序号</th>
                                        <th>文章标题</th>
                                        <th>文章分类</th>
                                        <th>创建时间</th>
                                        <th>修改时间</th>
                                        <th>状态</th>
                                        <th>PV</th>
                                        <th>点赞</th>
                                        <th>作者</th>
                                        <th>是否推荐</th>
                                        <th>操作</th></tr>
                                </thead>
                                <tbody>
                                {{range $key, $value := $.Data}}
                                    <tr>
                                        <td>{{IndexForOne $key $.Paginator.CurrentPage $.Paginator.PageSize}}</td>
                                        <td><a  href="/detail/{{$value.Id}}.html" target="_blank">{{$value.Title}}</a></td>
                                        <td>{{$value.Category.Name}}</td>
                                        <td>{{$value.Created}}</td>
                                        <td>{{$value.Updated}}</td>
                                        <td>{{index $.StatusText $value.Status}}</td>
                                        <td>{{$value.Pv}}</td>
                                        <th>{{$value.Like}}</th>
                                        <td>{{$value.User.Name}}</td>
                                        <td>
                                            <input type="checkbox" id="{{$value.Id}}" {{if eq $value.Recommend 1}}checked{{end}} name="recommend" lay-skin="switch" lay-filter="recommend" lay-text="{{index $.RecommendText $value.Recommend}}|{{index $.RecommendText $value.Recommend}}">
                                            {{/*{{index $.RecommendText $value.Recommend}}*/}}
                                        </td>

                                        <td class="td-manage">
                                            <a title="查看" onclick="xadmin.open('编辑','{{urlfor "admin.ArticleController.Put"}}?id={{$value.Id}}','','',true)" href="javascript:;">
                                                <i class="layui-icon">&#xe63c;</i></a>
                                            <a title="删除" onclick="member_del(this,'{{$value.Id}}')" href="javascript:;">
                                                <i class="layui-icon">&#xe640;</i></a>
                                        </td>
                                    </tr>
                                {{end}}
                                </tbody>
                            </table>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page" id="page">
                                <div>
                                    <span class="current">{{.Paginator.CurrentPage}}</span>
                                    {{if gt .Paginator.CurrentPage 1}}
                                        <a class="prev" href="{{urlfor "admin.ArticleController.List"}}?page={{IndexDecrOne $.Paginator.CurrentPage}}&start={{if .Start}}{{.Start}}{{end}}&end={{if .End}}{{.End}}{{end}}&status={{if .Status}}{{.Status}}{{end}}&title={{if .Title}}{{.Title}}{{end}}">上一页</a>
                                    {{end}}
                                    {{if lt .Paginator.CurrentPage .Paginator.TotalPage}}
                                        <a class="next" href="{{urlfor "admin.ArticleController.List"}}?page={{IndexAddOne $.Paginator.CurrentPage}}&start={{if .Start}}{{.Start}}{{end}}&end={{if .End}}{{.End}}{{end}}&status={{if .Status}}{{.Status}}{{end}}&title={{if .Title}}{{.Title}}{{end}}">下一页</a>
                                    {{end}}
                                    <span class="num">总 {{.Paginator.TotalPage}} 页</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script>
        layui.use(['laydate', 'form','laypage'],
            function() {
                var laydate = layui.laydate;
                var form = layui.form;
                //执行一个laydate实例
                laydate.render({
                    elem: '#start' //指定元素
                    ,format:'yyyy-MM-dd HH:mm:ss'
                });
                //执行一个laydate实例
                laydate.render({
                    elem: '#end' //指定元素
                    ,format:'yyyy-MM-dd HH:mm:ss'
                });


                //监听指定开关
                form.on('switch(recommend)', function(data){

                    //layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
                    //console.log($(this).attr("id"));
                    $.ajax({
                        url:'/admin/article/top',
                        type:'post',
                        data:'id='+$(this).attr("id"),
                        success:function (data) {
                            //发异步删除数据
                            window.location.reload();

                        }
                    });

                });
            }
        );

        /*删除*/
        function member_del(obj, id) {
            layer.confirm('确认要删除吗？',
            function(index) {
                $.ajax({
                    url:'/admin/article/delete',
                    type:'post',
                    data:'id='+id,
                    success:function (data) {
                        //发异步删除数据
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!', {
                            icon: 1,
                            time: 1000
                        });
                        window.location.reload();

                    }
                });
            });
        }

    </script>

</html>